package tq.com.tqteacher.optimize.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import tq.com.tqteacher.R;
import tq.com.tqteacher.model.TQNewPublish;
import tq.com.tqteacher.model.TQPublishType;

public class TQViewOptimizeCardDetailInfo extends FrameLayout {
    private TextView style0;
    private LinearLayout style1;
    private LinearLayout style2;

    private TextView style11;
    private TextView style12;

    private TextView style21;
    private TextView style22;
    private TextView style23;

    static public int STYLE0 = 0;
    static public int STYLE1 = 1;
    static public int STYLE2 = 2;

    private TextView title;
    private TextView content;

    private int showType = 0;
    public TQViewOptimizeCardDetailInfo(@NonNull Context context, @Nullable AttributeSet attrs){
        super(context, attrs);
        initUI();
    }

    private void initUI(){
        LayoutInflater.from(getContext()).inflate(R.layout.vh_publish_optimize_layout, this,true);

        style0 = findViewById(R.id.style0);
        style1 = findViewById(R.id.style1);
        style2 = findViewById(R.id.style2);

        style11 = findViewById(R.id.style11);
        style12 = findViewById(R.id.style12);

        style21 = findViewById(R.id.style21);
        style22 = findViewById(R.id.style22);
        style23 = findViewById(R.id.style23);

        style0.setOnClickListener(mOnClickListener);
        style11.setOnClickListener(mOnClickListener);
        style12.setOnClickListener(mOnClickListener);
        style21.setOnClickListener(mOnClickListener);
        style22.setOnClickListener(mOnClickListener);
        style23.setOnClickListener(mOnClickListener);

        title = findViewById(R.id.title);
        content = findViewById(R.id.content1);
        findViewById(R.id.content).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mIClickListener != null)mIClickListener.showDetail();
            }
        });

        switchStyle(0);
    }

    private void switchStyle(int type){
        style0.setVisibility(GONE);
        style1.setVisibility(GONE);
        style2.setVisibility(GONE);

        if(type == 0){
            style0.setVisibility(VISIBLE);
        }else if(type == STYLE1){
            style1.setVisibility(VISIBLE);
        }else{
            style2.setVisibility(VISIBLE);
        }
    }



    //pingjiang, weike
    private void showPingjiang(){
        switchStyle(STYLE1);
        showType = 1;

        style11.setText("参考数据");
        Drawable left = getResources().getDrawable(R.drawable.icon_cksj, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style11.setCompoundDrawables(left, null, null, null);

        style12.setText("整理留言");
        left = getResources().getDrawable(R.drawable.icon_zlly, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style12.setCompoundDrawables(left, null, null, null);
    }

    //同步、单元、复习、考卷  优化
    private void showFxj(){
        switchStyle(STYLE0);

        style0.setText("整理留言");
        Drawable left = getResources().getDrawable(R.drawable.icon_zlly, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style0.setCompoundDrawables(left, null, null, null);
    }
    private void showQTFX(){
        switchStyle(STYLE2);
        showType = 2;

        style21.setText("参考数据");
        Drawable left = getResources().getDrawable(R.drawable.icon_cksj, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style21.setCompoundDrawables(left, null, null, null);

        style22.setText("整理留言");
        left = getResources().getDrawable(R.drawable.icon_zlly, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style22.setCompoundDrawables(left, null, null, null);

        style23.setText("整理内容");
        left = getResources().getDrawable(R.drawable.icon_zlnr, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style23.setCompoundDrawables(left, null, null, null);
    }

    private void showTw_Dy(){
        switchStyle(STYLE1);
        showType = 3;

        style11.setText("参考数据");
        Drawable left = getResources().getDrawable(R.drawable.icon_cksj, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style11.setCompoundDrawables(left, null, null, null);

        style12.setText("整理提问");
        left = getResources().getDrawable(R.drawable.icon_zltw, null);
        left.setBounds(0, 0, left.getMinimumWidth(), left.getMinimumHeight());
        style12.setCompoundDrawables(left, null, null, null);
    }

    public void setBaseInfo(TQNewPublish pBaseInfo){
        if(pBaseInfo == null) return;

        title.setText(pBaseInfo.getName());
        content.setText(pBaseInfo.getDesc());

        if(pBaseInfo.getType() == TQPublishType.TYPE_JP
                || pBaseInfo.getType() == TQPublishType.TYPE_WK){
            showPingjiang();
        }else if(pBaseInfo.getType() == TQPublishType.TYPE_TWDY){
            showTw_Dy();
        }else if(pBaseInfo.getType() == TQPublishType.TYPE_QTFX){
            showQTFX();
        }else {
            showFxj();
        }
    }



    private OnClickListener mOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            if(mIClickListener == null) return;
            if(showType == 0 && v.getId() == R.id.style0){
                mIClickListener.arrageLeaveMsg();
            }else if(showType == 1){
                if(v.getId() == R.id.style11){
                    mIClickListener.dataStatices();
                }else if(v.getId() == R.id.style12){
                    mIClickListener.arrageLeaveMsg();
                }
            }else if(showType == 2){
                if(v.getId() == R.id.style21){
                    mIClickListener.dataStatices();
                }else if(v.getId() == R.id.style22){
                    mIClickListener.arrageLeaveMsg();
                }else if(v.getId() == R.id.style23){
                    mIClickListener.arrageContent();
                }
            }else if(showType == 3){
                if(v.getId() == R.id.style11){
                    mIClickListener.dataStatices();
                }else if(v.getId() == R.id.style12){
                    mIClickListener.arragQuestion();
                }
            }

        }
    };
    private IClickListener mIClickListener ;
    public void setIClickListener(IClickListener pIClickListener){
        mIClickListener = pIClickListener;
    }

    public interface IClickListener{
        void dataStatices();
        void arragQuestion();

        void arrageLeaveMsg();
        void arrageContent();

        void showDetail();
    }
}
